import 'package:flutter/material.dart';

/// 应用排版系统
/// 定义应用中使用的所有文本样式
class AppTypography {
  // 防止实例化
  AppTypography._();
  
  /// 标题样式
  static final headline = _HeadlineStyles();
  
  /// 正文样式
  static final body = _BodyStyles();
  
  /// 标签样式
  static final label = _LabelStyles();
  
  /// 按钮样式
  static final button = _ButtonStyles();
  
  /// 从主题数据创建应用排版
  static TextTheme createTextTheme(bool isDark) {
    final Color textColor = isDark ? Colors.white : Colors.black87;
    final Color secondaryTextColor = isDark ? Colors.white70 : Colors.black54;
    
    return TextTheme(
      // 大标题
      headlineLarge: headline.large.copyWith(color: textColor),
      headlineMedium: headline.medium.copyWith(color: textColor),
      headlineSmall: headline.small.copyWith(color: textColor),
      
      // 标题
      titleLarge: headline.titleLarge.copyWith(color: textColor),
      titleMedium: headline.titleMedium.copyWith(color: textColor),
      titleSmall: headline.titleSmall.copyWith(color: textColor),
      
      // 正文文本
      bodyLarge: body.large.copyWith(color: textColor),
      bodyMedium: body.medium.copyWith(color: textColor),
      bodySmall: body.small.copyWith(color: textColor),
      
      // 标签文本
      labelLarge: label.large.copyWith(color: textColor),
      labelMedium: label.medium.copyWith(color: textColor),
      labelSmall: label.small.copyWith(color: textColor),
    );
  }
}

/// 标题样式
class _HeadlineStyles {
  /// 大标题 - 大尺寸 (28px)
  final TextStyle large = const TextStyle(
    fontSize: 28.0,
    fontWeight: FontWeight.bold,
    letterSpacing: -0.5,
    height: 1.2,
  );
  
  /// 大标题 - 中尺寸 (24px)
  final TextStyle medium = const TextStyle(
    fontSize: 24.0,
    fontWeight: FontWeight.bold,
    letterSpacing: -0.25,
    height: 1.2,
  );
  
  /// 大标题 - 小尺寸 (20px)
  final TextStyle small = const TextStyle(
    fontSize: 20.0,
    fontWeight: FontWeight.bold,
    letterSpacing: 0,
    height: 1.25,
  );
  
  /// 标题 - 大尺寸 (18px)
  final TextStyle titleLarge = const TextStyle(
    fontSize: 18.0,
    fontWeight: FontWeight.bold,
    letterSpacing: 0,
    height: 1.25,
  );
  
  /// 标题 - 中尺寸 (16px)
  final TextStyle titleMedium = const TextStyle(
    fontSize: 16.0,
    fontWeight: FontWeight.w600,
    letterSpacing: 0,
    height: 1.25,
  );
  
  /// 标题 - 小尺寸 (14px)
  final TextStyle titleSmall = const TextStyle(
    fontSize: 14.0,
    fontWeight: FontWeight.w600,
    letterSpacing: 0,
    height: 1.25,
  );
}

/// 正文样式
class _BodyStyles {
  /// 正文 - 大尺寸 (16px)
  final TextStyle large = const TextStyle(
    fontSize: 16.0,
    fontWeight: FontWeight.normal,
    letterSpacing: 0.15,
    height: 1.5,
  );
  
  /// 正文 - 中尺寸 (14px)
  final TextStyle medium = const TextStyle(
    fontSize: 14.0,
    fontWeight: FontWeight.normal,
    letterSpacing: 0.25,
    height: 1.4,
  );
  
  /// 正文 - 小尺寸 (12px)
  final TextStyle small = const TextStyle(
    fontSize: 12.0,
    fontWeight: FontWeight.normal,
    letterSpacing: 0.4,
    height: 1.4,
  );
  
  /// 卡片内容样式
  final TextStyle cardContent = const TextStyle(
    fontSize: 14.0,
    fontWeight: FontWeight.normal,
    letterSpacing: 0.25,
    height: 1.4,
  );
  
  /// 描述文本样式
  final TextStyle description = const TextStyle(
    fontSize: 14.0,
    fontWeight: FontWeight.normal,
    letterSpacing: 0.25,
    height: 1.4,
    fontStyle: FontStyle.italic,
  );
}

/// 标签样式
class _LabelStyles {
  /// 标签 - 大尺寸 (14px)
  final TextStyle large = const TextStyle(
    fontSize: 14.0,
    fontWeight: FontWeight.w500,
    letterSpacing: 0.1,
    height: 1.25,
  );
  
  /// 标签 - 中尺寸 (12px)
  final TextStyle medium = const TextStyle(
    fontSize: 12.0,
    fontWeight: FontWeight.w500,
    letterSpacing: 0.1,
    height: 1.25,
  );
  
  /// 标签 - 小尺寸 (10px)
  final TextStyle small = const TextStyle(
    fontSize: 10.0,
    fontWeight: FontWeight.w500,
    letterSpacing: 0.1,
    height: 1.25,
  );
  
  /// 状态标签样式
  final TextStyle status = const TextStyle(
    fontSize: 12.0,
    fontWeight: FontWeight.bold,
    letterSpacing: 0.1,
    height: 1.25,
  );
  
  /// 计数标签样式
  final TextStyle count = const TextStyle(
    fontSize: 20.0,
    fontWeight: FontWeight.bold,
    letterSpacing: 0,
    height: 1.2,
  );
}

/// 按钮样式
class _ButtonStyles {
  /// 主按钮文本样式
  final TextStyle primary = const TextStyle(
    fontSize: 14.0,
    fontWeight: FontWeight.w500,
    letterSpacing: 0.5,
    height: 1.25,
  );
  
  /// 小型按钮文本样式
  final TextStyle small = const TextStyle(
    fontSize: 12.0,
    fontWeight: FontWeight.w500,
    letterSpacing: 0.5,
    height: 1.25,
  );
}

/// 文本样式扩展
extension TextStyleExtensions on TextStyle {
  /// 设置颜色
  TextStyle withColor(Color color) {
    return copyWith(color: color);
  }
  
  /// 设置字重
  TextStyle withWeight(FontWeight weight) {
    return copyWith(fontWeight: weight);
  }
  
  /// 设置斜体
  TextStyle withItalic() {
    return copyWith(fontStyle: FontStyle.italic);
  }
  
  /// 设置下划线
  TextStyle withUnderline() {
    return copyWith(decoration: TextDecoration.underline);
  }
  
  /// 设置删除线
  TextStyle withLineThrough() {
    return copyWith(decoration: TextDecoration.lineThrough);
  }
}

/// 文本样式辅助函数
/// 通过上下文获取文本样式
class AppTextStyles {
  // 防止实例化
  AppTextStyles._();
  
  /// 获取headline1样式
  static TextStyle headlineLarge(BuildContext context) {
    return Theme.of(context).textTheme.headlineLarge!;
  }
  
  /// 获取headline2样式
  static TextStyle headlineMedium(BuildContext context) {
    return Theme.of(context).textTheme.headlineMedium!;
  }
  
  /// 获取headline3样式
  static TextStyle headlineSmall(BuildContext context) {
    return Theme.of(context).textTheme.headlineSmall!;
  }
  
  /// 获取title1样式
  static TextStyle titleLarge(BuildContext context) {
    return Theme.of(context).textTheme.titleLarge!;
  }
  
  /// 获取title2样式
  static TextStyle titleMedium(BuildContext context) {
    return Theme.of(context).textTheme.titleMedium!;
  }
  
  /// 获取title3样式
  static TextStyle titleSmall(BuildContext context) {
    return Theme.of(context).textTheme.titleSmall!;
  }
  
  /// 获取bodyLarge样式
  static TextStyle bodyLarge(BuildContext context) {
    return Theme.of(context).textTheme.bodyLarge!;
  }
  
  /// 获取bodyMedium样式
  static TextStyle bodyMedium(BuildContext context) {
    return Theme.of(context).textTheme.bodyMedium!;
  }
  
  /// 获取bodySmall样式
  static TextStyle bodySmall(BuildContext context) {
    return Theme.of(context).textTheme.bodySmall!;
  }
  
  /// 获取labelLarge样式
  static TextStyle labelLarge(BuildContext context) {
    return Theme.of(context).textTheme.labelLarge!;
  }
  
  /// 获取labelMedium样式
  static TextStyle labelMedium(BuildContext context) {
    return Theme.of(context).textTheme.labelMedium!;
  }
  
  /// 获取labelSmall样式
  static TextStyle labelSmall(BuildContext context) {
    return Theme.of(context).textTheme.labelSmall!;
  }
} 